<%@page import="com.cysyz.web.modules.base.user.domain.SysUser" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="m" uri="/mytags" %>

<head>
    <title>用户列表</title>

    <script type="text/javascript">
        var oTable;
        require.config({
            paths: {
                "require-config": "/js/base/require.config"
            }
        });

        require(["require-config"], function () {

            require(["mytable", "validationEngine"], function () {
                $(function () {


                    oTable = $("#dataTable").MyTable({
                        ajax: {
                            url: "${controllerUrlPrefix}/search.do",
                            paramForm: "searchForm",
                            dataMaper: {
                                data: function (data) {

                                    data.data = data.content[0].records;
                                },
                                recordsTotal: function (data) {
                                    data.recordsTotal = data.content[0].totalRecords;
                                }
                            }
                        },
                        "columns": [

                            {"data": "<%=SysUser.ALIAS_LOGIN_NAME%>"},

                            {"data": "<%=SysUser.ALIAS_NAME%>"},

                            {"data": "<%=SysUser.ALIAS_EMAIL%>"},
                            {"data": "<%=SysUser.ALIAS_MOBILE%>"},

                            {"data": "<%=SysUser.ALIAS_CREATE_TIME%>"},

                            {"data": "<%=SysUser.ALIAS_LAST_LOGIN_IP%>"},

                            {"data": "<%=SysUser.ALIAS_LAST_LOGIN_TIME%>"},

                            {"data": "<%=SysUser.ALIAS_LOGIN_COUNT%>"},

                            {"data": "<%=SysUser.ALIAS_STATE%>"},

                        ],
                        addLinks:function(data){
                            //增加每行末尾的操作功能,没有可以不加此方法
                            var tdStr='<m:permissionA href="${controllerUrlPrefix}/editUI.do?id='+data.id+'" module="sysUser" moduleFunction="edit" title="编辑" />';

                            if (data.state=='lock') {
                                tdStr+= '<m:permissionA cssClass="unlockBtn" href="javascript:void(0);" id="'+data.id+'" module="sysUser" moduleFunction="unLock" title="恢复" />'
                            } else {
                                tdStr+= '<m:permissionA cssClass="lockBtn" href="javascript:void(0);" id="'+data.id+'" module="sysUser" moduleFunction="lock" title="停用" />'
                            }

                            return tdStr;
                        },
                        renderCell:function(row, cell, data) {
                            if(cell.index==8){
                               var state = cell.jdom.text();
                                if (state == 'lock') {
                                    cell.jdom.text("停用");
                                } else if(state == 'unLock') {
                                    cell.jdom.text("正常");

                                }
                            }
                        }

                    });

                    $(".lockBtn").live("click", function () {
                        if(confirm("是否确认停用该用户")) {
                            $.getJSON("${controllerUrlPrefix}/lock.do",
                                    {userId:$(this).attr("id")},
                                    function(data){
                                        if (data.result == "SUCCESS") {
                                            oTable.ajax.reload();
                                        } else {
                                            alert("停用失败");
                                        }
                                    });
                        }
                    });
                    $(".unlockBtn").live("click", function () {
                        if(confirm("是否确认恢复该用户")) {
                            $.getJSON("${controllerUrlPrefix}/unLock.do",
                                    {userId:$(this).attr("id")},
                                    function(data){
                                        if (data.result == "SUCCESS") {
                                            oTable.ajax.reload();
                                        } else {
                                            alert("恢复失败");
                                        }
                                    });
                        }
                    });

                    document.onkeydown = function (e) {
                        var ev = document.all ? window.event : e;
                        if (ev.keyCode == 13) {

                            oTable.ajax.reload();
                        }
                    };
                    $("#searchBtn").click(function () {
                        oTable.ajax.reload();
                    });

                    var validateOption = {
                        scroll: false,
                        ajaxFormValidation: true,
                        //binded:false,
                        //showArrow:false,
                        //promptPosition:"centerRight",
                        autoHidePrompt: false,
                        maxErrorsPerField: 1,
                        showOneMessage: true,
                        ajaxReturnIsSuccess:function (result) {
                            if (!result) {
                                return true;
                            } else {
                                return false;
                            }
                        }
                    };
                    $("#searchForm").validationEngine(validateOption);
                });
            });
        });
        function msg() {
            if (confirm("确定要删除？") == false) {
                return false;
            }
        }


    </script>
</head>

    <operationArea>

        <m:permissionA href="${controllerUrlPrefix}/addUI.do" module="sysUser" moduleFunction="add" cssClass="btn btn-default" title="添加" />

    </operationArea>


    <searchArea>
        <%--条件栏--%>
        <form id="searchForm" action="${controllerUrlPrefix}/search.do" method="post"
              onkeydown="if(event.keyCode==13){return false;}" class="form-inline">
            <div class="">
                <div class="form-group">
                    <label>账户:</label>
                    <input type="text" class="form-control " name="<%=SysUser.ALIAS_LOGIN_NAME%>"/>
                </div>
                <div class="form-group">
                    <label>姓名:</label>
                    <input type="text" class="form-control " name="<%=SysUser.ALIAS_NAME%>"/>
                </div>
                <div class="form-group">
                    <label>邮箱地址:</label>
                    <input type="text" class="form-control " name="<%=SysUser.ALIAS_EMAIL%>"/>
                </div>
                <div class="form-group">
                    <label>手机号:</label>
                    <input type="text" class="form-control " name="<%=SysUser.ALIAS_MOBILE%>"/>
                </div>
                <div class="form-group">
                    <label>状态:</label>
                    <select id="state" name="state" class="form-control">
                        <option value="">所有</option>
                        <option value="lock">停用</option>
                        <option value="unLock">正常</option>
                    </select>
                </div>

                <%--<div class="form-group">--%>
                    <%--<label>创建时间:</label>--%>
                    <%--<input type="text" class="form-control " name="<%=SysUser.ALIAS_CREATE_TIME%>Begin" onclick="WdatePicker()"/>---%>
                    <%--<input type="text" class="form-control" name="<%=SysUser.ALIAS_CREATE_TIME%>End" onclick="WdatePicker()"/>--%>

                <%--</div>--%>
                    <%--<div class="form-group">--%>
                        <%--<label>最后登录时间:</label>--%>
                        <%--<input type="text" class="form-control" name="<%=SysUser.ALIAS_LAST_LOGIN_TIME%>Begin" onclick="WdatePicker()"/>---%>
                        <%--<input type="text" class="form-control" name="<%=SysUser.ALIAS_LAST_LOGIN_TIME%>End" onclick="WdatePicker()"/>--%>
                    <%--</div>--%>

                <%--<div class="form-group">--%>

                    <%--<label>登录次数:</label>--%>
                    <%--<input type="text" class="form-control validate[custom[onlyNumberSp]]" name="<%=SysUser.ALIAS_LOGIN_COUNT%>Min"/>---%>
                    <%--<input type="text" class="form-control validate[custom[onlyNumberSp]]" name="<%=SysUser.ALIAS_LOGIN_COUNT%>Max"/>--%>
                <%--</div>--%>

                <a class="search_button" id="searchBtn"></a>
            </div>
        </form>
    </searchArea>

    <tableArea>
        <table class="tDefault tablewidth tCenter dataTable mb10" style="table-layout:fixed;" id="dataTable">
            <thead>
            <tr>
                <th class="sorting" align="center" style="width: 100px">账户</th>
                <th class="sorting" align="center" style="width: 60px">姓名</th>
                <th class="sorting" align="center" style="width: 80px;text-overflow:ellipsis;">邮箱地址</th>
                <th class="sorting" align="center" style="width: 60px">手机号码</th>
                <th class="sorting" align="center" style="width: 90px">创建时间</th>
                <th class="sorting" align="center" style="width: 80px">最后登陆IP</th>
                <th class="sorting" align="center" style="width: 90px">最后登录时间</th>
                <th class="sorting" align="center" style="width: 30px">登录次数</th>
                <th class="sorting" align="center" style="width: 40px">状态</th>
                <th class="sorting" align="center" style="width: 60px">操作</th>
            </tr>
            </thead>
        </table>
    </tableArea>

</html>
